<HTML>
  <HEAD>
  <TITLE> New Document </TITLE>
  <script>

  function newelement(){
  var a=document.createElement("a");
  a.href="javascript:alert('A link.')";
  a.innerHTML="aaa";
  var img=new Image();
  img.src="http://img.baidu.com/img/post-jg.gif";
  img.style.border="none";
  
  a.appendChild(img)
  document.getElementById("oData").appendChild(a);
  
  img.onmouseover=function(){
  this.src="http://www.baidu.com/img/sslm1_logo.gif";
  }
  
  img.onmouseout=function(){
  this.src="http://img.baidu.com/img/post-jg.gif";
  }
  }

  function handleDownload() {

    var name = "xxxx.gif";
    var url = "http://img.baidu.com/img/post-jg.gif";
    var suffix = url.substring(url.lastIndexOf("."), url.length);
    const a = document.createElement('a')
    a.setAttribute('download', name)
    a.setAttribute('target', '_blank')
    a.setAttribute('href', url)
    a.click()
    }
  
  
  </script>
  </HEAD>
  <BODY onload=newelement()>
           <SPAN ID="oData" ></SPAN>

        <input type="button" onclick="handleDownload()">aaaa</input>
  </BODY>